//
//  HYBaseTableViewController.swift
//  iOSWeibo
//
//  Created by why on 16/7/18.
//  Copyright © 2016年 王浩宇. All rights reserved.
//

import UIKit

class HYBaseTableViewController: UITableViewController {

    var userLogin = HYUserAccountViewModel.sharedUserAccountViewModel.userLogin
    
    override func loadView()
    {
        if userLogin {
            
            super.loadView()
        }
        else {
            
            self.view = visitorView
            
            visitorView.delegate = self
            
            setupVisitorView()
        }
    }
    
    ///设置访客视图
    private func setupVisitorView() {
        
        if self is HYHomeTableViewController {
            visitorView.startRotationAnimation()
        } else if self is HYMessageTableViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if self is HYDiscoverTableViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        } else if self is HYProfileTableViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewDidRegister")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewDidLogin")
    }
    
    
    lazy var visitorView: HYVisitorView = HYVisitorView()
}

extension HYBaseTableViewController: VisitorViewDelegate {
    
    func vistorViewDidRegister() {
        print("HYBaseTableViewController:\(__FUNCTION__)")
    }
    
    func vistorViewDidLogin() {
        let oauthVC = HYOauthViewController()
        self.presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
}

